<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>房屋信息操作</title>
    <script src="../../res/js/jquery-3.4.1.min.js"></script>
    <script src="../../res/layui/layui.js" charset="utf-8"></script>
    <script src="../../res/js/Tools.js"></script>
    <link rel="stylesheet" href="../../res/layui/css/layui.css" media="all">
    <link href="../../res/echarts/eleTree.css" rel="stylesheet"/>
    <script src="../../res/echarts/eleTree.js"></script>
    <script src="../../res/js/login_common.js" charset="utf-8"></script>
    <style type="text/css">
        body {
            padding: 10px;
        }
    </style>
</head>
<body>
<div class="layui-form">
    <form class="layui-form layui-form-pane" action="">
        <input type="hidden" id="clientId" name="clientId">
        <div class="layui-form-item">

            <div class="layui-inline">
                <label class="layui-form-label">客户名：</label>
                <div class="layui-input-inline">
                    <input type="text" name="clientName" id="clientName" lay-verify="required" placeholder="请输入客户名（必填）"
                           autocomplete="off"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">电话：</label>
                <div class="layui-input-inline">
                    <input type="text" name="clientPhone" id="clientPhone" placeholder="请输入电话（必填）"
                           lay-verify="required"
                           autocomplete="off"
                           class="layui-input">
                </div>

            </div>
            <div class="layui-inline">
                <label class="layui-form-label">来源：</label>
                <div class="layui-input-inline">
                    <select name="clientSource" id="clientSource" lay-filter="level">
                        <option value="">请选择来源</option>
                        <option value="扫街">扫街</option>
                        <option value="网络">网络</option>
                        <option value="转介绍">转介绍</option>
                        <option value="老客户">老客户</option>
                        <option value="贴条来电">贴条来电</option>
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">业态：</label>
                <div class="layui-input-inline">
                    <input type="text" name="clientIndustry" id="clientIndustry" lay-verify="required"
                           placeholder="请输入业态（必填）"
                           lay-verify="required"
                           autocomplete="off"
                           class="layui-input">
                </div>
            </div>
            <!--<div class="layui-inline">
                <label class="layui-form-label">编号：</label>
                <div class="layui-input-inline">
                    <input type="text" name="clientIdentity" id="clientIdentity" lay-verify="required"
                           placeholder="请输入编号（必填）"
                           autocomplete="off"
                           class="layui-input">
                </div>
            </div>-->
        </div>
        <div class="layui-form-item">

            <div class="layui-inline">
                <label class="layui-form-label">需求面积:</label>
                <div class="layui-input-inline" style="width: 100px;">
                    <input type="text" name="clientState" id="clientState" placeholder="㎡"
                           autocomplete="off"
                           class="layui-input">
                </div>
                <div class="layui-form-mid">-</div>
                <div class="layui-input-inline" style="width: 100px;">
                    <input type="text" name="clientStates" id="clientStates" placeholder="㎡"
                           autocomplete="off"
                           class="layui-input">
                </div>

            </div>
            <div class="layui-inline">
                <label class="layui-form-label">预算范围：</label>
                <div class="layui-input-inline" style="width: 100px;">
                    <input type="text" name="clientMoney" id="clientMoney" autocomplete="off" placeholder="￥"
                           class="layui-input">
                </div>
                <div class="layui-form-mid">-</div>
                <div class="layui-input-inline" style="width: 100px;">
                    <input type="text" name="clientPayment" id="clientPayment" autocomplete="off" placeholder="￥"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <div class="layui-form-item" pane="">
                    <label class="layui-form-label">性别</label>
                    <div class="layui-input-block">
                        <input type="radio" name="clientSex" value="1" title="男" checked="">
                        <input type="radio" name="clientSex" value="0" title="女">
                    </div>

                </div>
            </div>
        </div>

        <div class="layui-form-item">


        </div>
        <div class="layui-form-item">

        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-block">
                <textarea id="remark" name="remark" placeholder="请输入内容" class="layui-textarea"></textarea>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1" id="sub">立即提交</button>
            </div>
        </div>
    </form>
</div>
<script>
    var houses;
    layui.use(['form', 'layedit', 'laydate', 'layer'], function () {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate;
        // 修改赋值
        var clientId = getQueryString("clientId");

        //当电话框试去焦点时
        $("#clientPhone").blur(function () {

            var curValue = $("#clientPhone").val();
            if(curValue.length === 11){
                var url = "../../clientAction/findPhone";
                let data ;
                if(clientId){
                    data = {
                        clientPhone: curValue,
                        clientId:clientId
                    };
                }else{
                    data = {
                        clientPhone: curValue
                    };
                }

                $.post(url, data, function (obj) {
                    if (obj > 0) {
                        //初体验

                        //layer.alert('内容')
                        //第三方扩展皮肤

                        layer.alert('该客户已存在不可重复添加', {
                            icon: 2,
                            skin: 'layer-ext-moon' //该皮肤由layer.seaning.com友情扩展。关于皮肤的扩展规则，去这里查阅
                        });
                        $("#clientPhone").val("");
                    }
                }, "json");
            }else{
                layer.alert('请填写正确得电话号码', {
                    icon: 2,
                    skin: 'layer-ext-moon' //该皮肤由layer.seaning.com友情扩展。关于皮肤的扩展规则，去这里查阅
                });
                $("#clientPhone").val("");
                return false;
            }


            /*if ($.trim(curValue) == "") {

                $(this).val(this.defaultValue);

            }*/

        });

        //自定义验证规则
        form.verify({
            title: function (value) {
                if (value.length === 11) {
                    return '请填写正确得电话号码'
                }
            }
            , pass: [
                /^[\S]{6,12}$/
                , '密码必须6到12位，且不能出现空格'
            ]
            ,content: function(value){
                layedit.sync(editIndex);
            }
        });

        //监听提交
        form.on('submit(demo1)', function (data) {
            var url = "../../clientAction/addOrUpdate";
            /*console.info(data.field);
            var house = houses.getValue()
            if (house.length > 0) {
                $.each(houses.getValue(), function (index, item) {
                    house.push(item.value + "_" + item.name)
                })
            }
            data.field.houseId = house;*/


            $.post(url, data.field, function (obj) {
                if (obj.num == 1) {
                    console.info($("#clientId").val());
                    if ($("#clientId").val()) {
                        // window.parent.location.reload();//刷新父页面
                        layer.msg('修改成功', {icon: 1});
                        parent.layui.table.reload('test');
                    } else {
                        parent.layui.table.reload('test');//刷新父页面
                        var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                        parent.layer.close(index);
                    }

                }
            }, "json");
            return false;
        });

        //下拉复选框取值
        $("#demo1-getValue").on("click", function () {
            var selectArr = clients.getValue();

            console.info(selectArr);
        });
        //表单取值
        layui.$('#LAY-component-form-getval').on('click', function () {
            var data = form.val('example');
            alert(JSON.stringify(data));
        });


        if (clientId) {
            $("#clientId").val(clientId);
            var url = "../../clientAction/findById";
            var data = {"id": clientId};
            $.ajaxSettings.async = false;
            $.post(url, data, function (obj) {
                $("#clientName").val(obj.clientName);                  // 客户名称
                $("#clientIdentity").val(obj.clientIdentity);          // 编号
                $("#clientPhone").val(obj.clientPhone);                // 电话
                $("#clientState").val(obj.clientState);                // 需求面积
                $("#clientStates").val(obj.clientStates);                // 需求面积
                $("#clientIndustry").val(obj.clientIndustry);          // 业态
                $("#clientMoney").val(obj.clientMoney);                // 最低金额
                $("#clientPayment").val(obj.clientPayment);            // 最高金额
                $("#clientSource").val(obj.clientSource);              // 来源
                $("#remark").val(obj.remark);              // 备注
                $("#clientSource").find("option[value=" + obj.clientSource + "]").prop("selected", true);
                $("input[name=clientSex][value='0']").attr("checked", obj.clientSex == 0 ? true : false); // 性别
                $("input[name=clientSex][value='1']").attr("checked", obj.clientSex == 1 ? true : false); // 性别
                /*$("input[name=clientState][value='0']").attr("checked", obj.clientState == 0 ? true : false);
                $("input[name=clientState][value='1']").attr("checked", obj.clientState == 1 ? true : false);
                $("input[name=clientPayment][value='0']").attr("checked", obj.clientPayment == 0 ? true : false);
                $("input[name=clientPayment][value='1']").attr("checked", obj.clientPayment == 1 ? true : false);
                $("input[name=clientPayment][value='2']").attr("checked", obj.clientPayment == 2 ? true : false);
                $("input[name=clientPayment][value='3']").attr("checked", obj.clientPayment == 3 ? true : false);
                clients.setValue();*/
                form.render();
            }, "json")


        }


        // 查看
        /*var show = getQueryString("show");
        if (show) {
            document.getElementById('clientName').setAttribute('disabled', 'disabled')
            document.getElementById('clientName').setAttribute('disabled', 'disabled')
            document.getElementById('clientName').setAttribute('disabled', 'disabled')
            document.getElementById('clientName').setAttribute('disabled', 'disabled')
            document.getElementById('clientName').setAttribute('disabled', 'disabled')
            //$('#houses').removeAttr('onclick');//去掉a标签中的onclick事件
            $("#sub").hide();
        }*/
        /*form.verify({
            conten: function (value) {
                return layedit.sync(index);
            }
        });*/

        form.render();
    });

</script>


<!--
<script type="text/javascript">
    /**
     * 修改日历格式
     * @param dates
     * @returns {string}
     */
    function setDate(dates) {
        var date = new Date(dates);
        var month = date.getMonth() + 1;
        var day = date.getDate();
        var sdate = date.getFullYear() + "-"
        if (month < 10) {
            sdate += "0" + month + "-";
        } else {
            sdate += month + "-";
        }
        if (day < 10) {
            sdate += "0" + day;
        } else {
            sdate += day;
        }
        return sdate;
    }
</script>-->
</body>
</html>